<template>
  <div>
    {{$st}}
    <Header></Header>
    <Swiper :list="swiperList"></Swiper>
    <icons :list="iconList"></icons>
    <recommend :list="recommendList"></recommend>
    <weekend :list="weekendList"></weekend>
  </div>
</template>
<script>
import Header from './components/Header'
import Swiper from './components/Swiper'
import Icons from './components/Icons'
import Recommend from './components/Recommend'
import Weekend from './components/Weekend'
import axios from 'axios'
import { mapState } from 'vuex'

export default {
  data () {
    return {
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList:[],
      lastCity:''
    }
  },
  computed: {
    ...mapState(['city'])
  },
  components:{
    Header,
    Swiper,
    Icons,
    Recommend,
    Weekend
  },
  methods: {
    getHomeInfo () {
      axios.get('/api/index.json?city=' + this.city).then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {
      res = res.data
      if(res.ret && res.data) {
        let data = res.data
        this.swiperList = data.swiperList
        this.iconList = data.iconList
        this.recommendList = data.recommendList
        this.weekendList = data.weekendList
      }
    }
  },
  mounted() {
    this.getHomeInfo()
    this.lastCity = this.city
  },
  activated () {
    if(this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
    }
  },
  destroyed () {
    console.log('离开了')
  }
}
</script>
<style>

</style>
